<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">短剧管理</a>
            <a><cite>短剧分类</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">分类名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入分类名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="type" lay-filter="type"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
    </div>
</script>
    <script type="text/html" id="tbBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
    <script>
        let params = {
            elem: '#type'
            , toolbar: '#toolbarDemo'
            , url: '/admin/type/list' //数据接口
            , page: true //开启分页
            , id: 'type'
            , limit:15
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 80, sort: true,align:'center' }
                , { field: 'name', title: '分类名称',align:'center' }
                , { field: 'sort', title: '排序',align:'center' }
                , {
                    field: 'created_at', title: '创建时间', templet: function (d) {
                        return dayjsFormat(d.created_at)
                    },align:'center'
                }
                , { toolbar: '#tbBar', title: '操作',align:'center' }
            ]]
        }
        tableList(params)
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            insTb = table.render();
            table.on('toolbar(type)', function (obj) {
                var event = obj.event;
                x_admin_show('添加分类', './info.html', 650, 350);
            });

            table.on('tool(type)', function (obj) {
                var event = obj.event;
                if (event === 'del') {
                    DeleteAjax('/admin/type/delete', { id: obj.data.id, }, 'type')
                } else if (event === 'edit') {
                    x_admin_show('编辑分类', './info.html?id=' + obj.data.id, 650, 350);
                }
            });

        });

    </script>

</body>

</html>